package com.xingkeduo.business.operation.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ShopsServprodQuery;
import com.xingkeduo.pojo.table.ShopsServprodTable;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件概述
 *
 * @author wangxilong <wangxilong@xingkeduo.com>
 * @version id:v0.1 ${date}${time}
 * @package BeautyOS
 * @copyright Copyright (c) XKD 2019
 */
@Component
public class ShopsServprodService {
    private static final String NAMESPACE = ShopsServprodTable.class.getSimpleName();

    @Resource(name = "mysqlOperationDao")
    private DatabaseAccessObject<ShopsServprodTable, ShopsServprodQuery> dao;

    //查询一条
    public ShopsServprodTable selectByCode(long code) throws Throwable {
        ShopsServprodTable shopsServprodTable = dao.select(NAMESPACE, code);
        if (!CommonUtil.isEmpty(shopsServprodTable))
            return shopsServprodTable;
        return null;
    }

    //查询多条
    public List<ShopsServprodTable> selectLists(ShopsServprodQuery shopsServprodQuery) throws Throwable {
        List<ShopsServprodTable> shopsServprodTableList = dao.select(NAMESPACE, shopsServprodQuery);
        if (!CommonUtil.isEmpty(shopsServprodTableList))
            return shopsServprodTableList;
        return null;
    }

    //插入
    public int insert(ShopsServprodTable shopsServprodTable) throws Throwable {
        shopsServprodTable.setCode(IdentityUtil.nextId(IdentityUtil.Worker.USER));
        return dao.insert(NAMESPACE, shopsServprodTable);
    }

    //插入
    public int insertAll(List<ShopsServprodTable> shopsServprodTableList) throws Throwable {
//        shopsServprodTable.setCode(IdentityUtil.nextId(Worker.USER));
        return dao.insert(NAMESPACE,shopsServprodTableList);
    }

    //更新
    public int update(ShopsServprodTable shopsServprodTable) throws Throwable {
        return dao.update(NAMESPACE, shopsServprodTable);
    }

    //批量更新
    public int updateAll(ShopsServprodTable shopsServprodTable,ShopsServprodQuery shopsServprodQuery) throws Throwable {
        return dao.update(NAMESPACE, shopsServprodTable,shopsServprodQuery);
    }

    //删除
    public int delete(ShopsServprodTable shopsServprodTable) throws Throwable {
        return dao.update(NAMESPACE, shopsServprodTable);
    }
}
